'use strict';

const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;
  return app.model.define('category', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: STRING(30),
      allowNull: false,
      comment: '学校名称',
    },
    parent_id: {
      type: INTEGER,
      allowNull: false,
      comment: '父级id',
    },
    sort: {
      type: INTEGER,
      allowNull: false,
      comment: '排序',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      comment: '状态',
    },
    create_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    }
  }, {
    tableName: 'category',
    comment: '分类',
    timestamps: true, // 启用时间戳(createdAt, updatedAt)
    createdAt: 'create_time',
    updatedAt: 'updated_time'
  });
};
